﻿using System;
using System.Collections.Generic;
using System.Text;

using Kiiro.Common.Interfaces;
using Kiiro.Common.Utility;

namespace Kiiro.Common.Entities
{
    [Serializable]
    public class ActivityHistory : BaseEntity, IEntity
    {
        #region Private Properties

        private BaseEntity referencedItem;

        private string activityReferenceUrl;
        private List<ValidationMessage> activityReferenceUrlMessage = new List<ValidationMessage> ( );
        private ItemType activityItemType;
        private List<ValidationMessage> activityItemTypeMessage = new List<ValidationMessage> ( );
        private EventType eventType;
        private List<ValidationMessage> eventTypeMessage = new List<ValidationMessage> ( );

        #endregion

        #region Public Properties

        public BaseEntity ReferencedItem
        {
            get { return referencedItem; }
            set
            {
                if ( referencedItem != value )
                {
                    referencedItem = value;
                    UpdateEntity ( );
                }
            }
        }

        public string ActivityReferenceUrl
        {
            get { return activityReferenceUrl; }
            set
            {
                if ( activityReferenceUrl != value )
                {
                    activityReferenceUrl = value;
                    UpdateEntity();
                }
            }
        }

        public List<ValidationMessage> ActivityReferenceUrlMessage
        {
            get { return activityReferenceUrlMessage; }
            set
            {
                if ( activityReferenceUrlMessage != value )
                {
                    activityReferenceUrlMessage = value;
                    UpdateEntity();
                }
            }
        }

        public ItemType ActivityItemType
        {
            get { return activityItemType; }
            set
            {
                if ( activityItemType != value )
                {
                    activityItemType = value;
                    UpdateEntity();
                }
            }
        }

        public List<ValidationMessage> ActivityItemTypeMessage
        {
            get { return activityItemTypeMessage; }
            set
            {
                if ( activityItemTypeMessage != value )
                {
                    activityItemTypeMessage = value;
                    UpdateEntity();
                }
            }
        }

        public EventType EventType
        {
            get { return eventType; }
            set
            {
                if ( eventType != value )
                {
                    eventType = value;
                    UpdateEntity ( );
                }
            }
        }

        public List<ValidationMessage> EventTypeMessage
        {
            get { return eventTypeMessage; }
            set
            {
                if ( eventTypeMessage != value )
                {
                    eventTypeMessage = value;
                    UpdateEntity ( );
                }
            }
        }


        #endregion

        #region IEntity Members


        public new bool IsValid()
        {
            return AllValidationErrors().Count == 0;
        }

        public new List<ValidationMessage> AllValidationErrors()
        {
            List<ValidationMessage> allErrors = new List<ValidationMessage>();

            allErrors.AddRange ( activityReferenceUrlMessage );
            allErrors.AddRange ( activityItemTypeMessage );
            allErrors.AddRange ( eventTypeMessage );

            return allErrors;
        }

        public new void ClearValidationMessages()
        {
            activityReferenceUrlMessage.Clear ( );
            activityItemTypeMessage.Clear ( );
            eventTypeMessage.Clear ( );
        }
        
        #endregion

        #region Constructors

        /// <summary>
        /// Constructor
        /// </summary>
        public ActivityHistory ( )
        {
        }

        /// <summary>
        /// Constructor (copies BaseEntity properties ONLY to new ActivityHistory, no Permissions/License Key properties)
        /// </summary>
        /// <param name="baseEntity"></param>
        public ActivityHistory ( BaseEntity baseEntity )
        {
            this.ActivityReferenceUrl = baseEntity.ServerRelativeUrl;

            if ( baseEntity is Project )
            {
                this.CreatedBy = baseEntity.ModifiedBy;
                this.CreatedDate = baseEntity.ModifiedDate;
                this.ModifiedBy = baseEntity.ModifiedBy;
                this.ModifiedDate = baseEntity.ModifiedDate;
                this.ServerRelativeUrl = baseEntity.ServerRelativeUrl;
                this.SiteCollectionId = baseEntity.SiteCollectionId;
                this.Title = baseEntity.Title;
            }

            else if ( baseEntity is User )
            {
            }
        }

        #endregion // Constructors
    }
}

/*************************************************************************
 * 
 * $Log: /Internal Projects/Kiiro/Kiiro.Common/Entities/ActivityHistory.cs $
 * 
 * 4     17/08/09 10:38a Camerons
 * Added check-in comments section
 * 
 ************************************************************************/